home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Comunicatii / htttrack / httrack-3.32-2.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-08  |  13.7 KB  |  431 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTTRACK_DEFH
  39. #define HTTRACK_DEFH
  40.  
  41.  
  42. #include "htsglobal.h"
  43.  
  44. /* specific definitions */
  45. #include "htsbase.h"
  46. // Includes & dΘfinitions
  47. #ifdef HAVE_SYS_TYPES_H
  48. #include <sys/types.h>
  49. #endif
  50. #ifdef HAVE_SYS_STAT_H
  51. #include <sys/stat.h>
  52. #endif
  53. #ifdef _WIN32
  54. #ifndef  _WIN32_WCE
  55. #include <conio.h>
  56. #endif
  57. #ifndef  _WIN32_WCE
  58. #include <signal.h>
  59. #include <direct.h>
  60. #endif
  61. #else
  62. #include <signal.h>
  63. #ifdef HAVE_UNISTD_H
  64. #include <unistd.h>
  65. #endif
  66. #endif
  67. /* END specific definitions */
  68.  
  69.  
  70. // Include htslib.h for all types
  71. #include "htslib.h"
  72.  
  73. #include "htsopt.h"
  74.  
  75. // structure d'un lien
  76. typedef struct {
  77.   char firstblock;      // flag 1=premier malloc 
  78.   char link_import;     // lien importΘ α la suite d'un moved - ne pas appliquer les rΦgles classiques up/down
  79.   int depth;            // profondeur autorisΘe lien ; >0 forte 0=faible
  80.   int pass2;            // traiter aprΦs les autres, seconde passe. si == -1, lien traitΘ en background
  81.   int premier;          // pointeur sur le premier lien qui a donnΘ lieu aux autres liens du domaine
  82.   int precedent;        // pointeur sur le lien qui a donnΘ lieu α ce lien prΘcis
  83.   //int moved;          // pointeur sur moved
  84.   int retry;            // nombre de retry restants
  85.   int testmode;         // mode test uniquement, envoyer juste un head!
  86.   char* adr;            // adresse
  87.   char* fil;            // nom du fichier distant
  88.   char* sav;            // nom α sauver sur disque (avec chemin Θventuel)
  89.   char* cod;            // chemin codebase Θventuel si classe java
  90.   char* former_adr;     // adresse initiale (avant Θventuel moved), peut Ωtre nulle
  91.   char* former_fil;     // nom du fichier distant initial (avant Θventuel moved), peut Ωtre nul
  92.   // pour optimisation:
  93. #if HTS_HASH
  94.   int hash_next[3];     // prochain lien avec mΩme valeur hash
  95. #else
  96.   int sav_len;          // taille de sav
  97. #endif
  98. } lien_url;
  99.  
  100. // chargement de fichiers en 'arriΦre plan'
  101. typedef struct {
  102. #if DEBUG_CHECKINT
  103.   char magic;
  104. #endif
  105.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  106.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  107.   char url_sav[HTS_URLMAXSIZE*2];     // nom α sauver sur disque (avec chemin Θventuel)
  108.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  109.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  110.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  111.   char* tmpfile;                           // nom α sauver temporairement (compressΘ)
  112.   char tmpfile_buffer[HTS_URLMAXSIZE*2];   // buffer pour le nom α sauver temporairement
  113.   char send_too[1024];    // donnΘes α envoyer en mΩme temps que le header
  114.   int status;             // status (-1=non utilisΘ, 0: prΩt, >0: opΘration en cours)
  115.   int testmode;           // mode de test
  116.   int timeout;            // gΘrer des timeouts? (!=0  : nombre de secondes)
  117.   TStamp timeout_refresh; // si oui, time refresh
  118.   int rateout;            // timeout refresh? (!=0 : taux minimum tolΘrΘ en octets/s)
  119.   TStamp rateout_time;    // si oui, date de dΘpart
  120.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  121.   LLint maxfile_html;     // idem pour un ficheir html
  122.   htsblk r;               // structure htsblk de chaque objet en background 
  123.   int is_update;          // mode update
  124.   int head_request;       // requΦte HEAD?
  125.   LLint range_req_size;   // range utilisΘ
  126.   TStamp ka_time_start;   // refresh time for KA 
  127.   //
  128.   int http11;             // L'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  129.   int is_chunk;           // chunk?
  130.   char* chunk_adr;        // adresse chunk en cours de chargement
  131.   LLint chunk_size;       // taille chunk en cours de chargement
  132.   LLint chunk_blocksize;  // taille data declaree par le chunk
  133.   LLint compressed_size;  // taille compressΘs (stats uniquement)
  134.   //
  135.   int* pass2_ptr;         // pointeur sur liens[ptr]->pass2
  136.   //
  137.   char info[256];         // Θventuel status pour le ftp
  138.   int stop_ftp;           // flag stop pour ftp
  139.   int finalized;          // finalized (optim memory)
  140. #if DEBUG_CHECKINT
  141.   char magic2;
  142. #endif
  143. } lien_back;
  144.  
  145. typedef struct cache_back_zip_entry cache_back_zip_entry;
  146.  
  147. // cache
  148. typedef struct {
  149.   int version;        // 0 ou 1
  150.   /* */
  151.   int type;
  152.   int ro;
  153.   FILE *dat,*ndx,*olddat;
  154.   char *use;      // liste des adr+fil
  155.   FILE *lst;      // liste des fichiers pour la "purge"
  156.   FILE *txt;      // liste des fichiers (info)
  157.   char lastmodified[256];
  158.   // HASH
  159.   void* hashtable;
  160.   // HASH for tests (naming subsystem)
  161.   void* cached_tests;
  162.   // fichiers log optionnels
  163.   FILE* log;
  164.   FILE* errlog;
  165.   // variables
  166.   int ptr_ant;      // pointeur pour anticiper
  167.   int ptr_last;     // pointeur pour anticiper
  168.   //
  169.   void* zipInput;
  170.   void* zipOutput;
  171.   cache_back_zip_entry* zipEntries;
  172.   int zipEntriesOffs;
  173.   int zipEntriesCapa;
  174. } cache_back;
  175.  
  176. typedef struct {
  177.   lien_url** liens;                     // pointeur sur liens
  178.   int max_lien;                         // indice le plus grand rencontrΘ
  179.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  180. } hash_struct;
  181.  
  182. #if HTS_HASH
  183. #else
  184. #define hash_write(A,B)
  185. #endif
  186.  
  187. typedef struct {
  188.   FILE* lst;
  189.   char path[HTS_URLMAXSIZE*2];
  190. } filecreate_params;
  191.  
  192. /* Library internal definictions */
  193. #ifdef HTS_INTERNAL_BYTECODE
  194.  
  195. static int cache_writable(cache_back* cache) {
  196.   return (cache != NULL && ( cache->dat != NULL || cache->zipOutput != NULL ) );
  197. }
  198.  
  199. static int cache_readable(cache_back* cache) {
  200.   return (cache != NULL && ( cache->olddat != NULL || cache->zipInput != NULL ) );
  201. }
  202.  
  203. #endif
  204.  
  205. // Fonctions
  206.  
  207. // INCLUDES .H PARTIES DE CODE HTTRACK
  208.  
  209. // routine main
  210. #include "htscoremain.h"
  211.  
  212. // divers outils pour httrack.c
  213. #include "htstools.h"
  214.  
  215. // aide pour la version en ligne de commande
  216. #include "htshelp.h"
  217.  
  218. // gΘnΘration du nom de fichier α sauver
  219. #include "htsname.h"
  220.  
  221. // gestion ftp
  222. #include "htsftp.h"
  223.  
  224. // routine parser java
  225. #include "htsjava.h"
  226.  
  227. // gestion interception d'URL
  228. #include "htscatchurl.h"
  229.  
  230. // gestion robots.txt
  231. #include "htsrobots.h"
  232.  
  233. // routines d'acceptation de liens
  234. #include "htswizard.h"
  235.  
  236. // routines de regexp
  237. #include "htsfilters.h"
  238.  
  239. // gestion backing
  240. #include "htsback.h"
  241.  
  242. // gestion cache
  243. #include "htscache.h"
  244.  
  245. // gestion hashage
  246. #include "htshash.h"
  247. #include "htsinthash.h"
  248.  
  249. // gestion rΘentrance
  250. #include "htsnostatic.h"
  251.  
  252. // infos console
  253. #if HTS_ANALYSTE_CONSOLE
  254. #include "httrack.h"
  255. #endif
  256.  
  257. #include "htsdefines.h"
  258.  
  259. #include "hts-indextmpl.h"
  260.  
  261. // INCLUDES .H PARTIES DE CODE HTTRACK
  262.  
  263. //
  264.  
  265. /*
  266. typedef void  (* t_hts_htmlcheck_init)(void);
  267. typedef void  (* t_hts_htmlcheck_uninit)(void);
  268. typedef int   (* t_hts_htmlcheck_start)(httrackp* opt);
  269. typedef int   (* t_hts_htmlcheck_end)(void);
  270. typedef int   (* t_hts_htmlcheck_chopt)(httrackp* opt);
  271. typedef int   (* t_hts_htmlcheck)(char* html,int len,char* url_adresse,char* url_fichier);
  272. typedef char* (* t_hts_htmlcheck_query)(char* question);
  273. typedef char* (* t_hts_htmlcheck_query2)(char* question);
  274. typedef char* (* t_hts_htmlcheck_query3)(char* question);
  275. typedef int   (* t_hts_htmlcheck_loop)(lien_back* back,int back_max,int back_index,int lien_tot,int lien_ntot,int stat_time,hts_stat_struct* stats);
  276. typedef int   (* t_hts_htmlcheck_check)(char* adr,char* fil,int status);
  277. typedef void  (* t_hts_htmlcheck_pause)(char* lockfile);
  278. typedef void  (* t_hts_htmlcheck_filesave)(char* file);
  279. typedef int   (* t_hts_htmlcheck_linkdetected)(char* link);
  280. typedef int   (* t_hts_htmlcheck_xfrstatus)(lien_back* back);
  281. typedef int   (* t_hts_htmlcheck_savename)(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
  282. typedef int   (* t_hts_htmlcheck_sendhead)(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* outgoing);
  283. typedef int   (* t_hts_htmlcheck_receivehead)(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* incoming);
  284. */
  285.  
  286. // demande d'interaction avec le shell
  287. #if HTS_ANALYSTE
  288. //char HTbuff[1024];
  289. /*
  290. extern t_hts_htmlcheck_init       hts_htmlcheck_init;
  291. extern t_hts_htmlcheck_uninit     hts_htmlcheck_uninit;
  292. extern t_hts_htmlcheck_start      hts_htmlcheck_start;
  293. extern t_hts_htmlcheck_end        hts_htmlcheck_end;
  294. extern t_hts_htmlcheck_chopt      hts_htmlcheck_chopt;
  295. extern t_hts_htmlcheck            hts_htmlcheck;
  296. extern t_hts_htmlcheck_query      hts_htmlcheck_query;
  297. extern t_hts_htmlcheck_query2     hts_htmlcheck_query2;
  298. extern t_hts_htmlcheck_query3     hts_htmlcheck_query3;
  299. extern t_hts_htmlcheck_loop       hts_htmlcheck_loop;
  300. extern t_hts_htmlcheck_check      hts_htmlcheck_check;
  301. extern t_hts_htmlcheck_pause      hts_htmlcheck_pause;
  302. extern t_hts_htmlcheck_filesave   hts_htmlcheck_filesave;
  303. extern t_hts_htmlcheck_linkdetected hts_htmlcheck_linkdetected;
  304. extern t_hts_htmlcheck_xfrstatus  hts_htmlcheck_xfrstatus;
  305. extern t_hts_htmlcheck_savename   hts_htmlcheck_savename;
  306. extern t_hts_htmlcheck_sendhead   hts_htmlcheck_sendhead;
  307. extern t_hts_htmlcheck_receivehead hts_htmlcheck_receivehead;
  308. */
  309.  
  310. /* Library internal definictions */
  311. #ifdef HTS_INTERNAL_BYTECODE
  312.  
  313. //
  314. #ifndef HTTRACK_DEFLIB
  315. HTSEXT_API int hts_is_parsing(int flag);
  316. HTSEXT_API int hts_is_testing(void);
  317. HTSEXT_API int hts_is_exiting(void);
  318. HTSEXT_API int hts_setopt(httrackp* opt);
  319. HTSEXT_API int hts_addurl(char** url);
  320. HTSEXT_API int hts_resetaddurl(void);
  321. HTSEXT_API int copy_htsopt(httrackp* from,httrackp* to);
  322. HTSEXT_API char* hts_errmsg(void);
  323. HTSEXT_API int hts_setpause(int);      // pause transfer
  324. HTSEXT_API int hts_request_stop(int force);
  325. //
  326. HTSEXT_API char* hts_cancel_file(char * s);
  327. HTSEXT_API void hts_cancel_test(void);
  328. HTSEXT_API void hts_cancel_parsing(void);
  329. #endif
  330. //
  331. // Variables globales
  332. extern int _hts_in_html_parsing;
  333. extern int _hts_in_html_done;  // % rΘalisΘs
  334. extern int _hts_in_html_poll;  // parsing
  335. extern char _hts_errmsg[1100];
  336. extern int _hts_setpause;
  337. //extern httrackp* _hts_setopt;
  338. extern char** _hts_addurl;
  339. extern int _hts_cancel;
  340. #endif
  341.  
  342. //
  343.  
  344.  
  345. //int httpmirror(char* url,int level,httrackp opt);
  346. int httpmirror(char* url1,httrackp* opt);
  347. int filesave(httrackp* opt,char* adr,int len,char* s,char* url_adr /* = NULL */,char* url_fil /* = NULL */);
  348. int check_fatal_io_errno(void);
  349. int engine_stats(void);
  350. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,lien_back* back,int back_max,char* host);
  351. FILE* filecreate(char* s);
  352. int filecreateempty(char* filename);
  353. int filenote(char* s,filecreate_params* params);
  354. HTS_INLINE void usercommand(httrackp* opt,int exe,char* cmd,char* file,char* adr,char* fil);
  355. void usercommand_exe(char* cmd,char* file);
  356. //void* structcheck_init(int init);
  357. int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
  358. #ifndef HTTRACK_DEFLIB
  359. HTSEXT_API int structcheck(char* s);
  360. #endif
  361. HTS_INLINE int fspc(FILE* fp,char* type);
  362. char* next_token(char* p,int flag);
  363. //
  364. char* readfile(char* fil);
  365. char* readfile_or(char* fil,char* defaultdata);
  366. #if 0
  367. void check_rate(TStamp stat_timestart,int maxrate);
  368. #endif
  369.  
  370. // liens
  371. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  372.  
  373.  
  374. // backing, routines externes
  375. int back_fill(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  376. int backlinks_done(lien_url** liens,int lien_tot,int ptr);
  377. int back_fillmax(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  378.  
  379. // cancel file
  380. #if HTS_ANALYSTE
  381. #ifndef HTTRACK_DEFLIB
  382. HTSEXT_API char* hts_cancel_file(char * s);
  383. HTSEXT_API void hts_cancel_test(void);
  384. HTSEXT_API void hts_cancel_parsing(void);
  385. #endif
  386. #endif
  387.  
  388. int ask_continue(void);
  389. int nombre_digit(int n);
  390.  
  391. // Java
  392. #if 0
  393. int hts_add_file(char* file,int file_position);
  394. #endif
  395.  
  396. // Polling
  397. #if HTS_POLL
  398. HTS_INLINE int check_flot(T_SOC s);
  399. HTS_INLINE int check_stdin(void);
  400. int read_stdin(char* s,int max);
  401. #endif
  402. HTS_INLINE int check_sockerror(T_SOC s);
  403. HTS_INLINE int check_sockdata(T_SOC s);
  404.  
  405. httrackp* hts_declareoptbuffer(httrackp* optdecl);
  406. void sig_finish( int code );     // finir et quitter
  407. void sig_term( int code );       // quitter
  408. #if HTS_WIN
  409. void sig_ask( int code );        // demander
  410. #else
  411. void sig_back( int code );       // ignorer et mettre en backing 
  412. void sig_ask( int code );        // demander
  413. void sig_ignore( int code );     // ignorer signal
  414. void sig_brpipe( int code );     // treat if necessary
  415. void sig_doback(int);            // mettre en arriΦre plan
  416. #endif
  417.  
  418. /* external modules */
  419. int htsAddLink(htsmoduleStruct* str, char* link);
  420.  
  421. // Void
  422. void voidf(void);
  423.  
  424. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  425.  
  426. #endif
  427.  
  428. #endif
  429.  
  430.  
  431.